﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;

public partial class Admin_ucOrder : System.Web.UI.UserControl
{
    DateTime _dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // hien thi ngay dau tien - ngay cuoi cung trong thang
            _dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            DateTime date = _dt;
            date = date.AddMonths(1);
            date = date.AddDays(-(_dt.Day));

            txtFrDate.Text = _dt.ToString("dd/MM/yyyy");
            txtToDate.Text = DateTime.Now.ToString("dd/MM/yyyy");

            // so sanh hai ngay: ngay sau khong duoc nho hon nguoi truoc
            RangeValidator1.MinimumValue = new DateTime(1600, 01, 01).ToString("dd/MM/yyyy");
            RangeValidator1.MaximumValue = new DateTime(9999, 12, 31).ToString("dd/MM/yyyy");
            RangeValidator2.MinimumValue = new DateTime(1600, 01, 01).ToString("dd/MM/yyyy");
            RangeValidator2.MaximumValue = new DateTime(9999, 12, 31).ToString("dd/MM/yyyy");
        }
        if (Request.Params["__EVENTTARGET"] != null)
        {
            if (Request.Params["__EVENTTARGET"].IndexOf("DataPagerImages") > 0)
            {
                loaddata();
            }
        }
    }
    private void loaddata()
    {
        try 
        {
            TblOrderDAO orderDAO = new TblOrderDAO(Global.CONNECTION_STRING);
            DataTable dt = orderDAO.GetOrderList(Global.ConvertToDate(txtFrDate.Text), Global.ConvertToDate(txtToDate.Text), "", int.Parse(DropDownList1.SelectedValue.ToString()));
            lvItem.DataSource = dt;
            lvItem.DataBind();
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
    }

    protected void lvItem_PagePropertiesChanged(object sender, EventArgs e)
    {
        lvItem.DataBind();
    }
    protected void btnSubmit_Click1(object sender, ImageClickEventArgs e)
    {
        loaddata();
    }
}
